﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using OtherDevice;
using System.Diagnostics;
using CommonTools;
using System.Threading;
using StationCommunication;
using Newtonsoft.Json;

namespace ModuleUnit
{
    public class Config_SNOut
    {
        [Category("工站参数"), DisplayName("1.Ip地址 "), Description("Ip地址 ")]
        public string str_Ip地址 { set; get; } = "";
        [Category("工站参数"), DisplayName("1.Port "), Description("Port ")]
        public int n_Port { set; get; } = 8888;
    }
    [Description("发送SN")]
    public class Module_发送SN : ModuleBase
    {
        UnLoad_Interface Unload_Sever = UnLoadFactory.Mark(LoadType.Server);
        public Config_SNOut config = null;
        public Module_发送SN(object config, string strName) : base( strName)
        {
            if (config == null)
            {
                this.config = new Config_SNOut();
            }
            else
            {
                this.config = JsonConvert.DeserializeObject<Config_SNOut>(config.ToString());

            }
            this.obj_Config = this.config;
        }
        public override bool Init()
        {
            if (config.str_Ip地址 != "" && config.n_Port > 0)
                Unload_Sever.Run(config.str_Ip地址, config.n_Port);
            return true;
        } 
        public bool Function_SendSN(string strSN)
        {
            if (!Unload_Sever.IsLink())
            {
                return false;
            }
            Unload_Sever.SetStatus(DateTime.Now, true, strSN, "");
            return true;

        }
        public bool Function_IsLink()
        {
            return Unload_Sever.IsLink();
        }
    }
}